import random

import requests
from util.proxies import get_proxies_poll,get_proxies

proxy_poll = get_proxies_poll(2)
urls = [f"https://httpbin.org/get?age={i}" for i in range(100)]

while len(urls):
    url = urls.pop()
    proxy = random.choice(proxy_poll)
    try:
        res = requests.get(url, proxies=proxy)
        print(res.json())
    except requests.exceptions.ProxyError as e:
        print(f"代理{proxy}无效, 重新请求")
        proxy_poll.remove(proxy)
        proxy_poll.append(get_proxies())
        urls.append(url)
    except Exception as e:
        print(f"未知错误,错误原因{e}")
        urls.append(url)